package com.ruoyi.match.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.excel.EasyExcel;
import com.ruoyi.match.config.MyMapConvConvertStrategy;
import com.ruoyi.match.domain.ChOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.match.domain.ChNotice;
import com.ruoyi.match.service.IChNoticeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 撮合公告Controller
 * 
 * @author ruoyi
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/notice")
public class ChNoticeController extends BaseController
{
    @Autowired
    private IChNoticeService chNoticeService;


    @Autowired
    MyMapConvConvertStrategy myMapConvConvertStrategyl;


    /**
     * 查询撮合公告列表
     */
    @RequiresPermissions("match:notice:list")
    @GetMapping("/list")
    public TableDataInfo list(ChNotice chNotice)
    {
        startPage();
        List<ChNotice> list = chNoticeService.selectChNoticeList(chNotice);
        return getDataTable(list);
    }

    /**
     * 导出撮合公告列表
     */
    @RequiresPermissions("match:notice:export")
    @Log(title = "撮合公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChNotice chNotice) throws IOException {
        List<ChNotice> list = chNoticeService.selectChNoticeList(chNotice);
        EasyExcel.write(response.getOutputStream(),ChNotice.class)
                .registerConverter(myMapConvConvertStrategyl)
                .sheet("公告数据")
                .doWrite(list);
    }

    /**
     * 获取撮合公告详细信息
     */
    @RequiresPermissions("match:notice:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(chNoticeService.selectChNoticeById(id));
    }

    /**
     * 新增撮合公告
     */
    @RequiresPermissions("match:notice:add")
    @Log(title = "撮合公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChNotice chNotice)
    {
        return toAjax(chNoticeService.insertChNotice(chNotice));
    }

    /**
     * 修改撮合公告
     */
    @RequiresPermissions("match:notice:edit")
    @Log(title = "撮合公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChNotice chNotice)
    {
        return toAjax(chNoticeService.updateChNotice(chNotice));
    }

    /**
     * 删除撮合公告
     */
    @RequiresPermissions("match:notice:remove")
    @Log(title = "撮合公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(chNoticeService.deleteChNoticeByIds(ids));
    }
}
